/*
* Copyright (c) 2010 Michael Collins
*
* This file is part of TerraFirma.
*
* TerraFirma is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TerraFirma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TerraFirma.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "fixpoint.h"
#include <cstdio>
#include <math.h>

int main()
{
    using namespace fixedpoint;

    printf("RAW FIXPOINT CONSTANTS\n");
    printf("F_E: 0x%08x\n",fixpoint(M_E).raw());
    printf("F_LOG2E: 0x%08x\n",fixpoint(M_LOG2El).raw());
    printf("F_LOG10E: 0x%08x\n",fixpoint(M_LOG10El).raw());
    printf("F_LN2: 0x%08x\n",fixpoint(M_LN2l).raw());
    printf("F_LN10: 0x%08x\n",fixpoint(M_LN10l).raw());
    printf("F_PI: 0x%08x\n",fixpoint(M_PIl).raw());
    printf("F_PI_2: 0x%08x\n",fixpoint(M_PI_2l).raw());
    printf("F_PI_4: 0x%08x\n",fixpoint(M_PI_4l).raw());
    printf("F_1_PI: 0x%08x\n",fixpoint(M_1_PIl).raw());
    printf("F_2_PI: 0x%08x\n",fixpoint(M_2_PIl).raw());
    printf("F_2_SQRTPI: 0x%08x\n",fixpoint(M_2_SQRTPIl).raw());
    printf("F_SQRT2: 0x%08x\n",fixpoint(M_SQRT2l).raw());
    printf("F_SQRT1_2: 0x%08x\n\n",fixpoint(M_SQRT1_2l).raw());

    printf("RAW FIXPOINT TABLES\n");
    printf("Sine:\n");
    for(int i = 0; i < 256; i++)
        printf("0x%04x,\n",fixpoint(sin(i * M_PI_2 / 256)).raw());

    printf("\nArcsine:\n");
    for(int i = 0; i < 256; i++)
        printf("0x%04x,\n",fixpoint(M_2_PI * asin((double)i / 256)).raw());

    printf("\nInverse Square Root:\n");
    for(int i = 0; i < 32; i++) {
        double S = fixpoint(fixpoint::RAW, 1 << i);
        double R = 1.0f / sqrt(S);
        printf("0x%08x,\n",fixpoint(R).raw());
    }

    return 0;
}
